package org.openfans.web.remote;

import org.openfans.domain.Facade;
import org.openfans.domain.RootTag;
import org.openfans.domain.RootTagLink;

public class LinkManager {
	    private Facade facade=null;
	    
	   
		public void setFacade(Facade facade) {
			this.facade = facade;
		}
		
		private boolean validateLink(String url,String title){
			if ("".equals(title)){
				return false;
			}
			if (!url.startsWith("http://")){
				return false;
			}
			
			return true;
		}

		public String addLink(int tagId,String url,String title){
			if (!validateLink(url,title)){
				return "error";
			}
			
			RootTagLink rtl=new RootTagLink();
			rtl.setUrl(url);
			rtl.setTitle(title);
			RootTag rt=(RootTag)facade.getTag(tagId);
			rtl.setRootTag(rt);
			facade.save(rtl);
			
			return "ok";
		}
}
